<?php

require_once $_SERVER['DOCUMENT_ROOT'].'/myblog2/lib/Db.php';
// 登录
$username = $_POST['username'];
$password = $_POST['password'];

$db = new Db();

$user = $db->table('user')->where(array('username'=>$username))->item();


if(!$user){
	exit(json_encode(array('code'=>1,'msg'=>'用户不存在')));
}
if(md5($password)!=$user['password']){
	exit(json_encode(array('code'=>1,'msg'=>'密码错误')));
}
// 设置session
session_start();
$_SESSION['user'] = $user;
exit(json_encode(array('code'=>0,'msg'=>'登录成功')));
